"""
@File    :   no_introduction.py
@Time    :   2024/03/28 22:25:23
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   无需引入其他业务模块依赖(全局的no_introduction.py下的依赖项不包含在内)的依赖
"""


from typing import Annotated

from fastapi import Body, Depends, Header, Query
from sqlalchemy.ext.asyncio import AsyncSession

from src.business.admin.system.tenant.tenant.schemas.out import TenantCompleteOutSchema
from src.business.admin.system.tenant.tenant.service import TenantService
from src.dependencies.no_introduction import depend_get_master_db_session


class GetTenantIdDependencies:
    """获取租户ID的依赖类"""

    @staticmethod
    async def from_body(
        tenant_id: Annotated[int, Body(..., ge=1, description="租户ID")],
    ) -> int:
        """从json获取"""
        return tenant_id

    @staticmethod
    async def from_query(
        tenant_id: Annotated[int, Query(..., ge=1, description="租户ID")],
    ) -> int:
        """从query获取"""
        return tenant_id

    @staticmethod
    async def from_header(
        x_tenant_id: Annotated[int, Header(..., ge=1, description="租户ID")],
    ) -> int:
        """从header获取"""
        return x_tenant_id


class ValidateTenantExistsDependencies:
    """验证租户是否存在的依赖类"""

    @staticmethod
    async def from_body(
        tenant_id: Annotated[int, Depends(GetTenantIdDependencies.from_body)],
        db_session: Annotated[AsyncSession, Depends(depend_get_master_db_session)],
    ) -> TenantCompleteOutSchema:
        tenant: TenantCompleteOutSchema = await TenantService.get_tenant_use_id(
            db_session, tenant_id
        )
        return tenant

    @staticmethod
    async def from_query(
        tenant_id: Annotated[int, Depends(GetTenantIdDependencies.from_query)],
        db_session: Annotated[AsyncSession, Depends(depend_get_master_db_session)],
    ) -> TenantCompleteOutSchema:
        tenant: TenantCompleteOutSchema = await TenantService.get_tenant_use_id(
            db_session, tenant_id
        )
        return tenant

    @staticmethod
    async def from_header(
        tenant_id: Annotated[int, Depends(GetTenantIdDependencies.from_header)],
        db_session: Annotated[AsyncSession, Depends(depend_get_master_db_session)],
    ) -> TenantCompleteOutSchema:
        tenant: TenantCompleteOutSchema = await TenantService.get_tenant_use_id(
            db_session, tenant_id
        )
        return tenant
